import { FC, useState } from "react";
import { Button, ButtonProps } from "antd";

const LoadBtn: FC<ButtonProps> = ({ children, ...props }) => {
  const [isLoading, setIsLoading] = useState(false);
  return (
    <Button
      {...props}
      loading={isLoading}
      onClick={async (event) => {
        if (isLoading) return;
        setIsLoading(true);
        try {
          await props.onClick?.(event);
        } catch (e) {
          throw e
        } finally {
          setIsLoading(false)
        }
      }}
    >
      {children}
    </Button>
  );
};

export default LoadBtn;
